#pragma once

#include <cstdint>

#define NONE -1
#define SEAT_CLIMA_OFF 0
#define SEAT_CLIMA_LEVEL_1 1
#define SEAT_CLIMA_LEVEL_2 2
#define SEAT_CLIMA_LEVEL_3 3

// 座椅加热、通风全局变量
extern int32_t g_heatDrvrReqValue;
extern int32_t g_heatPassReqValue;
extern int32_t g_heatSecLeReqValue;
extern int32_t g_heatSecRiReqValue;
extern int32_t g_ventDrvrReqValue;
extern int32_t g_ventPassReqValue;
extern int32_t g_ventSecLeReqValue;
extern int32_t g_ventSecRiReqValue;

MAPPING_VALUE(sdb::SeatClimaLvl, int32_t, SEAT_CLIMA_OFF)
MAPPING_ITEM(sdb::SeatClimaLvl::Off, SEAT_CLIMA_OFF)
MAPPING_ITEM(sdb::SeatClimaLvl::Lvl1, SEAT_CLIMA_LEVEL_1)
MAPPING_ITEM(sdb::SeatClimaLvl::Lvl2, SEAT_CLIMA_LEVEL_2)
MAPPING_ITEM(sdb::SeatClimaLvl::Lvl3, SEAT_CLIMA_LEVEL_3)
MAPPING_END

MAPPING_VALUE(int32_t, sdb::SeatClimaLvl, sdb::SeatClimaLvl::Off)
MAPPING_ITEM(SEAT_CLIMA_OFF, sdb::SeatClimaLvl::Off)
MAPPING_ITEM(SEAT_CLIMA_LEVEL_1, sdb::SeatClimaLvl::Lvl1)
MAPPING_ITEM(SEAT_CLIMA_LEVEL_2, sdb::SeatClimaLvl::Lvl2)
MAPPING_ITEM(SEAT_CLIMA_LEVEL_3, sdb::SeatClimaLvl::Lvl3)
MAPPING_END

namespace ecarx::vhal::core::property::OpHmiSeatClimaStructUtil {
    inline bool isLeftRudder() {
        return !SIGNAL.carConfigIs(SignalRX::carconfig8, sdb::CarConfig8::_02);
    }

    inline OpHmiSeatClima_SetRequestNoReturn getCurrOpHmiSeatClima() {
        OpHmiSeatClima_SetRequestNoReturn climaValue;

        climaValue.hmiSeatClimaHmiSeatHeatgForRowFirstLe =
            isLeftRudder() ? (g_heatDrvrReqValue == NONE ? (uint8_t)SIGNAL.getDrvrSeatHeatgLvlSts() : (uint8_t)mappingValue(g_heatDrvrReqValue, sdb::SeatClimaLvl::Off))
            : (g_heatPassReqValue == NONE ? (uint8_t)SIGNAL.getPassSeatHeatgLvlSts() : (uint8_t)mappingValue(g_heatPassReqValue, sdb::SeatClimaLvl::Off));
        climaValue.hmiSeatClimaHmiSeatHeatgForRowFirstRi =
            isLeftRudder() ? (g_heatPassReqValue == NONE ? (uint8_t)SIGNAL.getPassSeatHeatgLvlSts() : (uint8_t)mappingValue(g_heatPassReqValue, sdb::SeatClimaLvl::Off))
            : (g_heatDrvrReqValue == NONE ? (uint8_t)SIGNAL.getDrvrSeatHeatgLvlSts() : (uint8_t)mappingValue(g_heatDrvrReqValue, sdb::SeatClimaLvl::Off));
        climaValue.hmiSeatClimaHmiSeatHeatgForRowSecLe =
            g_heatSecLeReqValue == NONE ? (uint8_t)SIGNAL.getSeatHeatgLvlStsRowSecLe() : (uint8_t)mappingValue(g_heatSecLeReqValue, sdb::SeatClimaLvl::Off);
        climaValue.hmiSeatClimaHmiSeatHeatgForRowSecRi =
            g_heatSecRiReqValue == NONE ? (uint8_t)SIGNAL.getSeatHeatgLvlStsRowSecRi() : (uint8_t)mappingValue(g_heatSecRiReqValue, sdb::SeatClimaLvl::Off);
        climaValue.hmiSeatClimaHmiSeatVentnForRowFirstLe =
            isLeftRudder() ? (g_ventDrvrReqValue == NONE ? (uint8_t)SIGNAL.getDrvrSeatVentnLvlSts() : (uint8_t)mappingValue(g_ventDrvrReqValue, sdb::SeatClimaLvl::Off))
            : (g_ventPassReqValue == NONE ? (uint8_t)SIGNAL.getPassSeatVentnLvlSts() : (uint8_t)mappingValue(g_ventPassReqValue, sdb::SeatClimaLvl::Off));
        climaValue.hmiSeatClimaHmiSeatVentnForRowFirstRi =
            isLeftRudder() ? (g_ventPassReqValue == NONE ? (uint8_t)SIGNAL.getPassSeatVentnLvlSts() : (uint8_t)mappingValue(g_ventPassReqValue, sdb::SeatClimaLvl::Off))
            : (g_ventDrvrReqValue == NONE ? (uint8_t)SIGNAL.getDrvrSeatVentnLvlSts() : (uint8_t)mappingValue(g_ventDrvrReqValue, sdb::SeatClimaLvl::Off));
        climaValue.hmiSeatClimaHmiSeatVentnForRowSecLe =
            (g_ventSecLeReqValue == NONE ? (uint8_t)SIGNAL.getSeatVentnLvlStsRowSecLe() : (uint8_t)mappingValue(g_ventSecLeReqValue, sdb::SeatClimaLvl::Off));
        climaValue.hmiSeatClimaHmiSeatVentnForRowSecRi =
            (g_ventSecRiReqValue == NONE ? (uint8_t)SIGNAL.getSeatVentnLvlStsRowSecRi() : (uint8_t)mappingValue(g_ventSecRiReqValue, sdb::SeatClimaLvl::Off));
        VHALOG.d("OpHmiSeatClimaStructUtil getCurrOpHmiSeatClima g_heatDrvrReqValue[%d], g_heatPassReqValue[%d], g_heatSecLeReqValue[%d], "
            "g_heatSecRiReqValue[%d], g_ventDrvrReqValue[%d], g_ventPassReqValue[%d], g_ventSecLeReqValue[%d], g_ventSecRiReqValue[%d]",
            g_heatDrvrReqValue, g_heatPassReqValue, g_heatSecLeReqValue, g_heatSecRiReqValue, g_ventDrvrReqValue, g_ventPassReqValue,
            g_ventSecLeReqValue, g_ventSecRiReqValue);
        return climaValue;
    }

}

using namespace ::ecarx::vhal::core::property::OpHmiSeatClimaStructUtil;